package com.relax.mybatis.plugin.sensitive.strategy.impl;

import org.apache.commons.lang3.StringUtils;

import com.relax.mybatis.plugin.sensitive.strategy.SensitiveStrategy;

/**
 * @author relax
 * @date 2022/07/05
 * @desc 中文姓名脱敏策略
 */
public class ChineseNameSensitiveStrategy implements SensitiveStrategy {

    /**
     * <p>中文姓名脱敏：显示第一个字</p>
     *
     * <pre>
     * ChineseNameSensitiveStrategy.handle("张三")    = "张*"
     * ChineseNameSensitiveStrategy.handle("西门吹雪") = "西***"
     * </pre>
     *
     * @param data
     * @param symbol
     * @return
     */
    @Override
    public String handle(String data, String symbol) {
        int length = StringUtils.length(data);
        if (length <= 1) {
            return data;
        }
        return StringUtils.rightPad(StringUtils.left(data, 1), length, symbol);
    }

}
